<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //es6中没有变量提升，必须先声明类
        class Father {
            constructor(x,y) {
                this.x=x
                this.y=y
            }
            money() {
                console.log(100);
            }
            sum(){
                console.log(this.x+this.y);
            }
            say(){
                return '我是爸爸'
            }
        }
        class Son extends Father {
            constructor(x,y){
                //必须在子类之前，用super调用父级元素
                super(x,y) //调用了父类中的构造函数
                this.x=x
                this.y=y
            }
            say(){
                // console.log('我是儿子');
                console.log(super.say());
            }
            sub(){
                console.log(this.x-this.y);
                
            }
        }
        
        var son = new Son(8,6);
        son.sub();
        // son.money();
        son.sum();
        // son.say();//如果实例化子类输出一个方法,先看子类有没有，没有才去父类中寻找执行
        //即就近原则
    </script>
</body>

</html>